<script type="text/javascript">
    $("#product-image").bind("click",function(){
      $("#fileToUpload").click();
    });
    function fileSelected(fileToUpload,target,id) {
        var file = document.getElementById(fileToUpload).files[0];
        if (file) {
            var fd = new FormData();
            fd.append("fileToUpload", document.getElementById(fileToUpload).files[0]);
            fd.append("target",target);
            fd.append("id",id);
            var xhr = new XMLHttpRequest();
            xhr.upload.addEventListener("progress", uploadProgress, false);
            xhr.addEventListener("load", uploadComplete, false);
            xhr.addEventListener("error", uploadFailed, false);
            xhr.addEventListener("abort", uploadCanceled, false);
            xhr.open("POST", "__APP__/Upload/book");//修改成自己的接口
            xhr.send(fd);
        }
    }

    function uploadProgress(evt) {
        // if (evt.lengthComputable) {
        //     var percentComplete = Math.round(evt.loaded * 100 / evt.total);
        //     document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';
        // }else {
        //     document.getElementById('progressNumber').innerHTML = 'unable to compute';
        // }
    }
        
    function uploadComplete(evt) {
        /* 服务器端返回响应时候触发event事件*/
        //alert(evt.target.responseText);
        var res= JSON.parse(evt.target.responseText);
        if(res.status==1){
            $('#'+res.target).attr("src", res.imgurl); 
            alert('上传成功');
        }else{
            alert(res.msg);
        }
    }
    function uploadFailed(evt) {
        alert("There was an error attempting to upload the file.");
    }
    function uploadCanceled(evt) {
        alert("The upload has been canceled by the user or the browser dropped the connection.");
    }
</script>
            <div class="row">
                <div class="col-lg-12">
                    <h3 class="page-header"><i class="fa fa-chevron-left" onclick="closeurl();"></i> 专家等级管理</h3>
                </div>
                <!-- /.col-lg-12 -->
            </div>



            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            编辑专家等级
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                                <form role="form">
                                    <div class="row">
                                        <div class="col-lg-4">
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">
                                                            <label>名称</label>
                                                            <input class="form-control" name="level" value="{$level.level}">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">
                                                            <label>单份病例价格</label>
                                                            <input class="form-control" type="number" name="recordprice" value="{$level.recordprice|intval}">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">
                                                            <label>订阅价格</label>
                                                            <input class="form-control" type="number" name="subprice" value="{$level.subprice|intval}">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">
                                                            <label>邀请评论价格</label>
                                                            <input class="form-control" type="number" name="discussprice" value="{$level.discussprice|intval}">
                                                        </div>
                                                    </div>
                                                </div>
                                        </div>
                                    </div>
                                    <center>
                                        <button type="button" class="btn btn-success" onclick="check()">提交</button>
                                        <button type="button" class="btn btn-danger" onclick="closeurl();">关闭</button>
                                    </center>
                                    </form>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->

        </div>

    <!-- Page-Level Demo Scripts - Tables - Use for reference -->
    <script>
        function check(){
            var level = $.trim($("input[name='level']").val());
            var recordprice = $.trim($("input[name='recordprice']").val());
            var subprice = $.trim($("input[name='subprice']").val());
            var discussprice = $.trim($("input[name='discussprice']").val());
            var id  = {$level.id};
            if(!level){
                $("input[name='level']").parent().addClass('has-error');
                return;
            }
            if(!recordprice || isNaN(recordprice)){
                $("input[name='recordprice']").parent().addClass('has-error');
                return;
            }
            if(!subprice || isNaN(subprice)){
                $("input[name='subprice']").parent().addClass('has-error');
                return;
            }
            if(!discussprice || isNaN(discussprice)){
                $("input[name='discussprice']").parent().addClass('has-error');
                return;
            }                                   
            $.post('__APP__/Level/edit',
                    {
                    id:id,
                    level:level,
                    recordprice:recordprice,
                    subprice:subprice,
                    discussprice:discussprice,
                    },
                function(data){
                    if(data.status==1){
                        alert('操作成功');
                        gourl('__APP__/Level');
                    }else{
                        alert('操作失败');
                    }
            });

        }
    </script>

</body>

</html>
